package _base0;

/**
 * 852. 山脉数组的峰顶索引
 */
public class No852 {
    public int peakIndexInMountainArray(int[] arr) {
        int left = 0, right = arr.length - 1;
        while (true) {
            int mid = (left + right) / 2;
            if (mid == 0 || mid == arr.length - 1 || (arr[mid] > arr[mid - 1] && arr[mid] > arr[mid + 1])) return mid;
            else if (arr[mid] < arr[mid - 1]) right = mid;
            else left = mid + 1;
        }
    }
}
